home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / HYP / E-G / Externals.cpt / Externals / card_3653.txt < prev    next >
Text File  |  1989-02-26  |  4KB  |  100 lines

  1. -- card: 3653 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 2795
  5. -- name: NewMenu
  6.  
  7.  
  8. -- part 1 (button)
  9. -- low flags: 00
  10. -- high flags: 8003
  11. -- rect: left=315 top=307 right=329 bottom=379
  12. -- title width / last selected line: 0
  13. -- icon id / first selected line: 0 / 0
  14. -- text alignment: 1
  15. -- font id: 0
  16. -- text size: 12
  17. -- style flags: 0
  18. -- line height: 16
  19. -- part name: Demo
  20. ----- HyperTalk script -----
  21. on mouseUp
  22.   push this card
  23.   visual effect iris open
  24.   go to card id 10546
  25. end mouseUp
  26.  
  27.  
  28.  
  29. -- part contents for background part 20
  30. ----- text -----
  31. 7
  32.  
  33. -- part contents for background part 1
  34. ----- text -----
  35. XFCN
  36.  
  37. -- part contents for background part 22
  38. ----- text -----
  39. NewMenu("Title","Item 1","Item 2",...,"Item n")
  40.  
  41. -- part contents for background part 13
  42. ----- text -----
  43. NewMenu is an XFCN (external function) that allows you to add your own menus to a HyperCard stack.  You may have up to eight menus with up to 15 items per menu.  
  44.  
  45. The number the NewMenu function returns is a reference number to the menu you just installed.  You MUST have this number to delete or make changes to the menu later on!  
  46.  
  47. When you change userLevels, or select paint tools, or do anything to cause HyperCard to change the menu bar--your new menu will be erased from the menu bar.  It is NOT gone from memory, just from the menu bar.  To have it replaced automatically do the "on idle" routine shown below.  This will make sure your menu is showing whenever you are in browse mode (on idle is not called when you're in button, field, or paint tools mode).
  48.  
  49. Add an item like "(-" to insert a divider line between menu options.  You may also end items with a slash letter (as is "An item/I") to add command keys.
  50.  
  51. All this would generally be done in a stack's script as follows:
  52.  
  53. on openStack  --  display new menus
  54.   global menu1, menu2  --  keep the "handles" to the menus in these globals
  55.   put NewMenu("Beep","Once","Twice","(-","Boing/9") into menu1
  56.   if menu1 is 0 then answer("Unable to make menu 'BEEP'") with "Drat"
  57.   put NewMenu("Visual","Effect 1") into menu2
  58.   if menu2 is 0 then answer("Unable to make menu 'Visual'") with "Drat"
  59. end openStack
  60.  
  61. on closeStack  --  delete the menus we've created using the globals saved in openStack
  62.   global menu1, menu2
  63.   put DeleteMenu(menu1) into menu1  --  clearing global for safety
  64.   put DeleteMenu(menu2) into menu2
  65. end closeStack
  66.  
  67. on idle  --  call ShowMenu every so often just in case our menus vanished
  68.   global menu1, menu2, lastTick
  69.   if (the ticks-lastTick)>120 then  --  gives better performance than on every iteration
  70.     put the ticks into lastTick
  71.     ShowMenu(menu1)
  72.     ShowMenu(menu2)
  73.   end if
  74.   pass idle
  75. end idle
  76.  
  77. on doMenu which  --  get our menu items from doMenu before HyperCard does...
  78.   global menu1, menu2  -- for CheckMenu and EnableMenu below
  79.   if which is "Once" then
  80.     beep 1
  81.     get CheckMenu(menu1,1,true)
  82.   else if which is "Twice" then
  83.     beep 1
  84.     wait 4
  85.     beep 1
  86.     get CheckMenu(menu1,2,true)
  87.   else if which is "Boing" then
  88.     play "Boing"
  89.     get CheckMenu(menu1,4,true)
  90.   else if which is "Effect 1" then
  91.     push card
  92.     visual effect dissolve to black
  93.     pop card
  94.     get EnableMenu(menu2,1,false)
  95.     else pass doMenu  --  Remember to pass on menu commands you don't trap!
  96. end doMenu
  97.  
  98. Notice that if you want the menu to appear for all cards in the stack, you would place the NewMenu function in the stack's script and install it "on openStack" and remove it "on closeStack".  If you wanted a menu to appear only for a certain background, the commands would be in that background's script and done "on openBackground" and "on closeBackground".  And the commands to make a menu to appear only on a certain card would be done in that card's script "on openCard"/"on closeCard".
  99.  
  100.